﻿using System.Web.Mvc;

namespace TaskManager.Web.Filters
{
    /// <summary>
    /// Action logging attribute
    /// </summary>
    public class LogAttribute : ActionFilterAttribute
    {
        private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(LogAttribute));

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (Log.IsDebugEnabled)
            {
                string action = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName + "." +
                   filterContext.ActionDescriptor.ActionName;
                Log.Debug("Entering " + action);
            }
        }

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (Log.IsDebugEnabled)
            {
                string action = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName + "." +
                   filterContext.ActionDescriptor.ActionName;
                Log.Debug("Leaving " + action);
            }
        }
    }
}